﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UPMS.Core.Domain.Mapping
{
    public class RoleMap : BaseMap<Role>
    {
        public RoleMap()
        {
            this.ToTable("Upms_tbl_Role");
            this.Property(r => r.Name).HasColumnName("Name").HasMaxLength(64);
            this.Property(r => r.ApplicationId).HasColumnName("ApplicationId").IsOptional();
            this.Property(r => r.GroupId).HasColumnName("GroupId").IsOptional();

            this.HasOptional(r => r.Application).WithMany(a => a.Roles).HasForeignKey(r => r.ApplicationId);
            this.HasOptional(r => r.Group).WithMany(g => g.Roles).HasForeignKey(r => r.GroupId);

            this.HasMany(r => r.Permissions).WithMany(p => p.Roles)
               .Map(m =>
               {
                   m.ToTable("Upms_tbl_Role_Permission");
                   m.MapLeftKey("RoleId");
                   m.MapRightKey("PermissionId");
               });
        }
    }
}
